stage.set_background_color("black")
amount = 10
speed = 5
color_list = ["purple", "yellow", "red"]
stage.disable_all_walls()
def click():
x = stage.click_x()
y = stage.click_y()
particle_list = []
# add other actions...
stage.event_click(click)
t = codesters.Teacher()
loops = t.find_block('for')
defs = t.find_text('def')
handler = t.find_text('event_click')
try:
tval1 = int(loops[0][0])
except:
tval1 = 0
try:
tval2 = int(defs[0][0])
except:
tval2 = 0
try:
tval3 = int(handler[0][0])
except:
tval3 = 0
try:
tval4 = t.get_indent_at_line(tval1)
except:
tval4 = -1
try:
tval5 = loops[0][1].replace(" ", "")
except:
tval5 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 != 0 and tval2 < tval1 < tval3, "Great Job!")
t1.add_failure(tval1 == 0, "Did you add a Loop with Range command?")
t1.add_failure(tval1 < tval2, "Oops! Make sure your loop is after the def click(): line!")
t1.add_failure(tval3 < tval2, "Oops! Make sure your loop is before the .event_click() line!")
t2 = TestObjective()
t2.add_success(tval1 != 0 and tval4 == 4 and tval5 == 'forcolorincolor_list:', "Great job!")
t2.add_failure(tval4 == -1, "Did you drag out a Loop with Range command?")
t2.add_failure(tval4 != 4, "Oops! Make the loop is indented once!")
t2.add_failure('value' in tval5, "Did you change value to color?")
t2.add_failure('my_list' in tval5, "Did you change my_list to color_list?")
t2.add_failure(tval5 != 'forcolorincolor_list:', "Did you change the loop correctly?")
################################################
# Pass test code
# - set pass_required to True if pass is required to prevent bad input error
# - include tpass before t1 in the test list
pass_required = True
passes = t.find_text("pass")
num_pass_only = 0
for p in passes:
if p[1].lower().replace(' ','') == "pass":
num_pass_only += 1
tpass = TestObjective()
if not pass_required:
tpass.add_success(num_pass_only == 0, "Great job!")
tpass.add_creative(num_pass_only > 0, "Great job! Feel free to delete pass statements now.")
################################################
tester = TestManager()
tester.add_test_list([tpass, t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)